package com.mjk.common.tools.xml.conver;

import com.mjk.common.tools.xml.conver.impl.BeeNullConverter;
import com.mjk.common.tools.xml.conver.impl.LinkedHashMapConverter;
import com.mjk.common.tools.xml.conver.impl.LinkedTreeMapConverter;
import com.mjk.common.tools.xml.conver.impl.MapConverter;
import com.thoughtworks.xstream.converters.Converter;

import java.util.ArrayList;
import java.util.List;

/**
 * xml conver enum
 */
public enum BeeXmlConverType {
    LinkedTreeMap(new LinkedTreeMapConverter()),
    LinkedHashMap(new LinkedHashMapConverter()),
    Map(new MapConverter()),
    NULL(new BeeNullConverter())
    ;
    Converter converter;

    BeeXmlConverType(Converter adapter) {
        this.converter = adapter;
    }

    public static List<Converter> getAllConverter(boolean isNull) {
        List<Converter> list = new ArrayList<>();
        for (BeeXmlConverType type : BeeXmlConverType.values()) {
            //如果不需要注册空值转换器，则跳过
            if (NULL.converter.equals(type.converter) && !isNull) {
                continue;
            }
            list.add(type.converter);
        }
        return list;
    }
}
